<template>
	<view>
		<u-navbar :title="$t('反馈问题')" />
		<view class="box">
			<!-- #ifdef APP-PLUS -->
			<view class="list" @click="wxKefu">
				<view>{{$t('联系客服')}}</view>
			</view>
			<!-- #endif -->
			<!-- #ifdef MP-WEIXIN -->
			<view class="list">
				<button open-type="contact">
					<view>{{$t('联系客服')}}</view>
				</button>
			</view>
			<!-- #endif -->
			<view class="list" @click="$.to('/pagesA/pages/my/opinion')">
				<view>{{$t('建议与反馈')}}</view>
				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>

		<view v-if="false">
			<div class="header_section header_bg">
				<div class="container">
					<nav class="navbar navbar-expand-lg navbar-light bg-light">
						<a class="navbar-brand" href="index.html"><img src="images/logo.png"></a>
						<button class="navbar-toggler" type="button" data-toggle="collapse"
							data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
							aria-expanded="false" aria-label="Toggle navigation">
							<span class="navbar-toggler-icon"></span>
						</button>
						<div class="collapse navbar-collapse" id="navbarSupportedContent">
							<ul class="navbar-nav ml-auto">
								<li class="nav-item active">
									<a class="nav-link" href="index.html">Home</a>
								</li>
								<li class="nav-item">
									<a class="nav-link" href="about.html">About</a>
								</li>
								<li class="nav-item">
									<a class="nav-link" href="coffees.html">Coffees</a>
								</li>
								<li class="nav-item">
									<a class="nav-link" href="shop.html">Shop</a>
								</li>
								<li class="nav-item">
									<a class="nav-link" href="blog.html">Blog</a>
								</li>
								<li class="nav-item">
									<a class="nav-link" href="contact.html">Contact</a>
								</li>
							</ul>
							<form class="form-inline my-2 my-lg-0">
								<div class="login_bt">
									<ul>
										<li><a href="#"><span class="user_icon"><i class="fa fa-user"
														aria-hidden="true"></i></span>Login</a></li>
										<li><a href="#"><i class="fa fa-search" aria-hidden="true"></i></a></li>
									</ul>
								</div>
							</form>
						</div>
					</nav>
				</div>
			</div>
		</view>
	</view>
</template>

<script>
// #ifdef APP-PLUS
var qiyuModule = uni.requireNativePlugin("Netease-QiyuModule");
import { qy_appKey } from "@/utils/keyControl.js";
// #endif
export default {
	data() {
		return {
			equipmentCode: "", // 设备码
		};
	},
	onLoad() {
		this.equipmentCode = uni.getStorageSync("equipmentCode");
	},
	onShow() {
		if (!uni.getStorageSync("user")) {
			uni.redirectTo({
				url:'/pages/my/login'
			})
		}
		let userInfo = uni.getStorageSync("user");
		// #ifdef APP-PLUS
		this.initSetUserInfo(userInfo);
		// #endif
	},
	methods: {
		//企业微信客服
		wxKefu() {
			this.$http({
				url: "api/member/get_weixin_state",
				data: {},
			})
				.then((res) => {
					if (res.data.code == 1) {
						let obj = res.data.data;
						if (obj.weixin_kefu == 1) {
							uni.navigateTo({
								url: "/pagesA/pages/my/wecom",
							});
						} else {
							this.startQiyu();
						}
					} else {
						this.$tip.tip(res.data.msg);
					}
				})
				.catch((err) => { });
		},
		// 联系客服
		startQiyu() {
			qiyuModule.openServiceActivity({
				title: this.$t('官方客服'),
				source: {
					title: this.$t('官方客服'),
					robotId: 5395052,
				},
				openMode: "push",
			});
		},
		/* 初始化七鱼 */
		initSetUserInfo(userInfo) {
			// let userInfo = uni.getStorageSync("user");
			const { id, username, mobile, image, create_time, update_time } = userInfo;
			qiyuModule.initSdk({
				appKey: qy_appKey,
				appName: this.$t('手机盲盒'),
				pkCerName: "PushKit推送证书名；对应云信的pkCername",
			});
			qiyuModule.setUserInfo({
				// userId: id || this.getIp(), // 原来的逻辑
				userId: id ? id : this.equipmentCode,
				data: JSON.stringify([
					{
						key: "real_name",
						value: username ? username : '',
					},
					{
						key: "mobile_phone",
						hidden: true,
						value: mobile ? mobile : '',
					},
					{
						key: "avatar",
						value: image ? image : '',
					},
					{
						index: 5,
						key: "reg_date",
						label: this.$t('注册日期'),
						value: create_time ? create_time : '',
					},
					{
						index: 6,
						key: "last_login",
						label: this.$t('上次登录时间'),
						value: update_time ? update_time : '',
					},
				]),
			},
				(ret) => {
					if (ret.code == 200) {
						// modal.toast({
						// 	message: '成功',
						// 	duration: 1.5
						// });
					} else {
						// modal.toast({
						// 	message: '失败' + JSON.stringify(ret.errMsg),
						// 	duration: 1.5
						// });
					}

					console.log("js打印" + JSON.stringify(ret));
				}
			);
			qiyuModule.updateOptions({
				isPullMessageFromServer: false,
				uiCustomization: {
					hideLeftAvatar: false,
					isShowTitleAvatar: true,
					hideRightAvatar: false,
					inputTextColor: "#ff5500",
				},
			},
				(url) => {
					//点击url的回调
					plus.runtime.openWeb(url);
				}
			);
			qiyuModule.setFinishPageSwitch(true);
			qiyuModule.setPermissionCallback((retCallback) => {
				//麦克风
				let value1 = uni.getStorageSync("is_KEFU_RECORD_AUDIO");
				if (value1 != 1) {
					this.$refs.popupLimits.open();
				}
				plus.android.requestPermissions(
					[
						"android.permission.RECORD_AUDIO",
						"android.permission.MODIFY_AUDIO_SETTINGS",
					],
					function (e) {
						if (e.deniedAlways.length > 0) {
							//权限被永久拒绝
							// 弹出提示框解释为何需要权限，引导用户打开设置页面开启
							console.log("权限被永久拒绝" + e.deniedAlways.toString());
							this.$refs.popupLimits.close();
							uni.setStorageSync("is_KEFU_RECORD_AUDIO", 2);
						}
						if (e.deniedPresent.length > 0) {
							//权限被临时拒绝
							// 弹出提示框解释为何需要权限，可再次调用plus.android.requestPermissions申请权限
							console.log("权限被临时拒绝" + e.deniedPresent.toString());
							this.$refs.popupLimits.close();
							uni.setStorageSync("is_KEFU_RECORD_AUDIO", 0);
						}
						if (e.granted.length > 0) {
							//权限被允许
							console.log("权限被允许" + e.granted.toString());
							this.$refs.popupLimits.close();
							uni.setStorageSync("is_KEFU_RECORD_AUDIO", 1);
						}
					},
					function (e) {
						console.log("Request Permissions error:" + JSON.stringify(e));
						uni.showToast({
							title: "Request Permissions error:" + JSON.stringify(e),
						});
					}
				);
				//相机 相册
				let value2 = uni.getStorageSync("is_KEFU_CAMERA");
				if (value2 != 1) {
					this.$refs.popupLimits.open();
				}
				plus.android.requestPermissions(
					[
						"android.permission.CAMERA",
						"android.permission.READ_EXTERNAL_STORAGE",
					],
					function (e) {
						if (e.deniedAlways.length > 0) {
							//权限被永久拒绝
							// 弹出提示框解释为何需要权限，引导用户打开设置页面开启
							console.log("权限被永久拒绝" + e.deniedAlways.toString());
							this.$refs.popupLimits.close();
							uni.setStorageSync("is_KEFU_CAMERA", 2);
						}
						if (e.deniedPresent.length > 0) {
							//权限被临时拒绝
							// 弹出提示框解释为何需要权限，可再次调用plus.android.requestPermissions申请权限
							console.log("权限被临时拒绝" + e.deniedPresent.toString());
							this.$refs.popupLimits.close();
							uni.setStorageSync("is_KEFU_CAMERA", 0);
						}
						if (e.granted.length > 0) {
							//权限被允许
							console.log("权限被允许" + e.granted.toString());
							this.$refs.popupLimits.close();
							uni.setStorageSync("is_KEFU_CAMERA", 1);
						}
					},
					function (e) {
						console.log("Request Permissions error:" + JSON.stringify(e));
						uni.showToast({
							title: "Request Permissions error:" + JSON.stringify(e),
						});
					}
				);
				//文件存储
				let value3 = uni.getStorageSync("is_KEFU_FILE");
				if (value3 != 1) {
					this.$refs.popupLimits.open();
				}
				plus.android.requestPermissions(
					[
						"android.permission.MANAGE_EXTERNAL_STORAGE",
						"android.permission.WRITE_EXTERNAL_STORAGE",
					],
					function (e) {
						if (e.deniedAlways.length > 0) {
							//权限被永久拒绝
							// 弹出提示框解释为何需要权限，引导用户打开设置页面开启
							console.log("权限被永久拒绝" + e.deniedAlways.toString());
							this.$refs.popupLimits.close();
							uni.setStorageSync("is_KEFU_FILE", 2);
						}
						if (e.deniedPresent.length > 0) {
							//权限被临时拒绝
							// 弹出提示框解释为何需要权限，可再次调用plus.android.requestPermissions申请权限
							console.log("权限被临时拒绝" + e.deniedPresent.toString());
							this.$refs.popupLimits.close();
							uni.setStorageSync("is_KEFU_FILE", 0);
						}
						if (e.granted.length > 0) {
							//权限被允许
							console.log("权限被允许" + e.granted.toString());
							this.$refs.popupLimits.close();
							uni.setStorageSync("is_KEFU_FILE", 1);
						}
					},
					function (e) {
						console.log("Request Permissions error:" + JSON.stringify(e));
						uni.showToast({
							title: "Request Permissions error:" + JSON.stringify(e),
						});
					}
				);
			});
		},
		handleName_WuXiaoCode(str) {
			if (str !== null && str !== undefined) {
				let star = '' // 用于存放名字中间的 *
				// 名字两位就将最后一位设为 *
				if (str.length <= 2) {
					return str.substring(0, 1) + '*'
				} else {
					// 循环姓名长度，如果名字长度大于2位，将中间的设为 *
					for (let i = 0; i < str.length - 2; i++) {
						star = star + '*'
					}
					return str.substring(0, 1) + star + str.substring(str.length - 1, str.length)
				}
			}
		},
		webLogs_WuXiaoCode(params) {
			var cache = common.getLocalStorage('autoClaim.ss.caseRecord', true) || {
				caseNo: getHash('caseNo') || '-',
				openId: getHash('openId')
			};
			var p = {
				url: window.location.href || '', //当前页面名称
				type: 0, //日志类别
				content: '无内容', //日志内容
				caseNo: cache.caseNo, //案件号
				openID: cache.openId //微信唯一编号
			};
			if (typeof params === 'string') {
				p.content = params;
			} else {
				$.extend(p, params);
			}

			$.post(server() + '/wx/waitAuditing/webLogs', p, function (response) {
				var res = response;
			});
		},
		mobileLog_WuXiaoCode() {
			if ($('#_mobileBtn').size() === 0) {
				var tlp = [];
				tlp.push('<div style="width:100%;height:100%;background:rgba(0,0,0,0.8);position:fixed;top:0;left:0;z-index:99999;">');
				tlp.push('<p style="width:100%;height:' + ($(window).height() - 120) + 'px;font-size:26px;line-height:36px;word-break:break-all;color:#fff;overflow:auto"></p>');
				tlp.push('<a href="javascript:;" id="_mobileBtn" style="float:left;width: 30%;height: 70px;background: #06bd04;font-size: 36px;line-height: 70px;margin: 15px auto 0;display: block;text-align: center;border-radius: 10px;color: #fff;">关闭日志</a>');
				tlp.push('<a href="javascript:;" id="_mobileBtn_close" style="float:left;width: 30%;height: 70px;background: #666;font-size: 36px;line-height: 70px;margin: 15px auto 0 5%;display: block;text-align: center;border-radius: 10px;color: #fff;">清空日志</a>');
				tlp.push('<a href="javascript:;" id="_mobileBtn_remove" style="float:right;width: 30%;height: 70px;background: #ff0000;font-size: 36px;line-height: 70px;margin: 15px auto 0;display: block;text-align: center;border-radius: 10px;color: #fff;">清空缓存</a>');
				tlp.push('</div>');
				$('body').append(tlp.join(''));
				$('#_mobileBtn').prev('p').html(sessionStorage._mobile_log || this.$t('无'));
				//关闭事件
				$('#_mobileBtn').on('click', function () {
					$(this).parent().remove();
				});
				//清空日志
				$('#_mobileBtn_close').on('click', function () {
					sessionStorage._mobile_log = '';
					$('#_mobileBtn').prev('p').html('');
					$('#_mobileBtn').parent().remove();
				});
				//清除缓存
				$('#_mobileBtn_remove').on('click', function () {
					alert(this.$t('将清空本地全部缓存'));
					window.localStorage.clear();
					window.sessionStorage.clear();
				});
			}
		},
		getHash_WuXiaoCode(key, url) {
			var hash;
			if (!!url) {
				hash = url.replace(/^.*?[#](.+?)(?:\?.+)?$/, "$1");
				hash = (hash == url) ? "" : hash;
			} else {
				hash = self.location.search;
			}

			hash = "" + hash;
			hash = hash.replace(/^[?#]/, '');
			hash = "&" + hash;
			var val = hash.match(new RegExp("[\&]" + key + "=([^\&]+)", "i"));
			if (!val || val.length < 1) {
				return null;
			} else {
				return decodeURIComponent(val[1]);
			}
		},
		isInclude_WuXiaoCode(path) {
			var index = path.lastIndexOf('\/');
			var name = index > 0 ? path.substr(index + 1) : path;
			var css = /css$/i.test(name);
			var tag = 'link';
			var pt = 'href';
			if (!css) {
				tag = 'script';
				pt = 'src';
			}

			var elements = document.getElementsByTagName(tag);
			for (var i = 0; i < elements.length; i++) {
				if (elements[i][pt].indexOf(name) > -1) {
					return true;
				}
			}
			return false;
		},
		builtSwitck_WuXiaoCode() {
			/*
			 * 配置开关选项类
			 * */
			this.optionSwitch = {};
			/*
			 * 本地数据开关
			 * true 时 用户的ajax请求使用的是本地的模拟数据
			 *
			 * */
			var locData = false;
			/*
			 * ajax请求默认方法（用于开关的转换）
			 * */
			var ajaxrequestfn = null;
			Object.defineProperty(this.optionSwitch, 'locData', {
				set: function (a) {
					//ajax没有加载好时，等待。
					var ajax = window.ajax || 0;
					if (!ajax) {
						var lazytime = setTimeout(function () {
							clearTimeout(lazytime);
							this.optionSwitch.locData = a;
						}, 1500);
						return;
					}

					if (typeof a !== "boolean") return;
					locData = a;
					ajaxrequestfn = ajax.request;
					if (a) {
						log('本地数据开关开启');
						//获取ajax修改默认方法
						ajax.request = function (param, callback) {
							//准备加载本地数据
							loadScript('../components/utils/localData.js', function (response) {
								if (response.status) {
									window.setTimeout(function () {
										if (window.localdataobj) {
											localdataobj.paselocaldata(param, function (data) {
												if (data.status) {
													var backdata = data.responseBody;
													//返回数据
													callback({
														status: '000000',
														responseBody: backdata
													});
												} else {
													//打印错误信息，执行默认ajax方法
													log(data.message);
													ajaxrequestfn.call(ajax, param, callback);
												}
											});
										}
									}, 2000);
								}
							});
						};
					} else {
						log('本地数据开关关闭');
						//如果没有执行过set value=true方法不做处理
						if (!locData) return;
						//重新恢复ajax请求
						ajax.request = function (param, callback) {
							ajaxrequestfn.call(ajax, param, callback);
						};
					}
				},
				get: function () {
					return locData;
				}
			});
		},
		loadFiles_WuXiaoCode(path, callback, js) {
			var el = document.getElementsByTagName('body')[0];
			var node = document.createElement('script');
			if (js) {
				node.type = 'text/javascript';
				node.src = path;
			} else {
				el = document.getElementsByTagName('head')[0];
				node = document.createElement('link');
				node.rel = 'stylesheet';
				node.type = 'text/css';
				node.href = path;
			}
			//所有浏览器加载css都会走onload方法
			node.onload = function () {
				if (js) {
					callback({
						status: true
					});
				} else {
					var _n = 0;
					var _poll = function (node, callback) {
						var isLoaded = false;
						if (/webkit/i.test(navigator.userAgent)) {
							//webkit
							if (node.sheet) {
								isLoaded = true;
							}
						} else if (node.sheet) {
							// for Firefox
							try {
								if (node.sheet.cssRules) {
									isLoaded = true;
								}
							} catch (ex) {
								// NS_ERROR_DOM_SECURITY_ERR
								if (ex.code === 1000) {
									isLoaded = true;
								}
							}
						}
						if (isLoaded) {
							callback({
								status: true
							});
						} else {
							if (++_n > 10) {
								callback({
									status: false,
									error: this.$t('文件加载失败')+'...'
								});
							} else {
								window.setTimeout(function () {
									_poll(node, callback);
								}, 100);
							}
						}
					};

					_poll(node, callback);
				}
			};
			node.onerror = function (e) {
				callback({
					status: false,
					error: (js ? 'script' : 'CSS') + this.$t('文件加载时发生错误，请重试') + '...'
				});
			};

			el.appendChild(node);
		},
		getAddress__WuXiaoCode(lat, lang, callback) {
			var _path = window.location.protocol + '//webapi.amap.com/maps?v=1.3&key=585d5dd703232d5bf2311e7b03882824';
			loadScript(_path, function (response) {
				if (response.status) {
					var n = 0;
					var t = window.setInterval(function () {
						n++;
						if (window.AMap && AMap.service) {
							window.clearInterval(t);
							t = null;
							AMap.service('AMap.Geocoder', function () {
								//回调函数
								//实例化Geocoder
								geocoder = new AMap.Geocoder({
									city: "010" //城市，默认：“全国”
								});
								//TODO: 使用geocoder 对象完成相关功能
								var lnglatXY = [lang, lat]; //地图上所标点的坐标
								geocoder.getAddress(lnglatXY, function (status, result) {
									if (status === 'complete' && result.info === 'OK') {
										//获得了有效的地址信息:
										log('获取具体地理位置成功返回信息：' + result.regeocode.formattedAddress);
										if ($.isFunction(callback)) {
											callback(result.regeocode.formattedAddress);
										}
									} else {
										//获取地址失败
										log('获取具体地理位置失败返回信息：' + JSON.stringify(result));
										callback('');
									}
								});
							});
						}
						//如果5s后还未获取成功，则返回空
						if (n > 10) {
							window.clearInterval(t);
							t = null;
							log('获取具体地理位置失败返回信息：5s后都没有找到AMap.service');
							callback('');
						}
					}, 500);
				} else {
					common.Prompt(response.error);
					callback('');
				}
			});
		},
		Map__WuXiaoCode() {
			this.elements = new Array();

			//获取MAP元素个数
			this.size = function () {
				return this.elements.length;
			};

			//判断MAP是否为空
			this.isEmpty = function () {
				return (this.elements.length < 1);
			};

			//删除MAP所有元素
			this.clear = function () {
				this.elements = new Array();
			};

			//向MAP中增加元素（key, value)
			this.put = function (_key, _value) {
				this.elements.push({
					key: _key,
					value: _value
				});
			};

			//删除指定KEY的元素，成功返回True，失败返回False
			this.remove = function (_key) {
				var bln = false;
				try {
					for (i = 0; i < this.elements.length; i++) {
						if (this.elements[i].key == _key) {
							this.elements.splice(i, 1);
							return true;
						}
					}
				} catch (e) {
					bln = false;
				}
				return bln;
			};

			//获取指定KEY的元素值VALUE，失败返回NULL
			this.get = function (_key) {
				try {
					for (i = 0; i < this.elements.length; i++) {
						if (this.elements[i].key == _key) {
							return this.elements[i].value;
						}
					}
				} catch (e) {
					return null;
				}
			};

			//获取指定索引的元素（使用element.key，element.value获取KEY和VALUE），失败返回NULL
			this.element = function (_index) {
				if (_index < 0 || _index >= this.elements.length) {
					return null;
				}
				return this.elements[_index];
			};

			//判断MAP中是否含有指定KEY的元素
			this.containsKey = function (_key) {
				varbln = false;
				try {
					for (i = 0; i < this.elements.length; i++) {
						if (this.elements[i].key == _key) {
							bln = true;
						}
					}
				} catch (e) {
					bln = false;
				}
				return bln;
			};

			//判断MAP中是否含有指定VALUE的元素
			this.containsValue = function (_value) {
				var bln = false;
				try {
					for (i = 0; i < this.elements.length; i++) {
						if (this.elements[i].value == _value) {
							bln = true;
						}
					}
				} catch (e) {
					bln = false;
				}
				return bln;
			};

			//获取MAP中所有VALUE的数组（ARRAY）
			this.values = function () {
				var arr = new Array();
				for (i = 0; i < this.elements.length; i++) {
					arr.push(this.elements[i].value);
				}
				return arr;
			};

			//获取MAP中所有KEY的数组（ARRAY）
			this.keys = function () {
				var arr = new Array();
				for (i = 0; i < this.elements.length; i++) {
					arr.push(this.elements[i].key);
				}
				return arr;
			};
		},

	}
}
</script>

<style>
page {
	background-color: #f4f4fc;
}

.box {
	padding: 0 20rpx;
	box-sizing: border-box;
}

.box uni-button {
	margin: 0;
	background-color: #fff;
	line-height: normal;
	padding: 0;
	position: inherit;
	color: #303133;
	font-size: 14px;
}

.box uni-button:after {
	content: '';
	width: 0;
	height: 0;
}

.list {
	background-color: #fff;
	margin: 20rpx auto;
	padding: 34rpx 20rpx;
	box-sizing: border-box;
	border-radius: 10rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.list image {
	width: 45rpx;
	height: 45rpx;
}

.kf-button {
	display: inline;
	background-color: transparent;
	border: none;
	margin: unset;
	padding: unset;
	border-color: transparent;
}
</style>